package com.xxxx.controller;

import com.xxxx.pojo.UserForm;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created By ShaoXikai on 2022/7/15
 */
@Controller
@RequestMapping("/user")
public class UserFormController {

    @GetMapping("/toLogin")
    public String toLogin() {
        return "login";
    }

    @PostMapping("/log")
    @ResponseBody
    public String login(String uname, String upwd) {
        System.out.println(uname + upwd);
        if (uname.equals("admin") && upwd.equals("admin")) {
            return "ok";
        } else {
            return "no";
        }
    }

    @GetMapping("/register")
    public String toReg() {
        return "register";
    }

    // @RequestMapping(path="/reg",produces="text/html;charset=UTF-8")
    @PostMapping(path = "/reg", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String reg(UserForm userForm) {
        String msg = "";
        if (userForm.getUpwd().equals(userForm.getConfirmPwd())) {
            msg = "注册成功";
            return msg;
        }
        msg = "注册失败，两次输入的密码不一致";
        return msg;
    }

}